package com.yyh.javase1;

import java.math.BigDecimal;

public class BigDecimalTest1 {
    public static void main(String[] args) {
        double num1 = 0.1D;
        double num2 = 0.2D;
        System.out.println(num1 + num2);//0.30000000000000004
        BigDecimal b1 = new BigDecimal("0.1");
        BigDecimal b2 = new BigDecimal("0.2");
        System.out.println(b1.add(b2));
        //绝对值
        System.out.println(b1.abs());
        //减法
        System.out.println(b1.subtract(b2));
        //乘法
        System.out.println(b1.multiply(b2));
        //除法
        System.out.println(b1.divide(b2));
        System.out.println(b1.divide(b2, 2, BigDecimal.ROUND_HALF_UP));
    }
}
